package ee.example.final_work

import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import androidx.annotation.RequiresApi
import androidx.fragment.app.Fragment
import com.example.final_work.R
import com.youth.banner.Banner
import com.youth.banner.indicator.CircleIndicator
import ee.example.final_work.Data.initView

class TabFragment_Home : Fragment() {
//    inner class RoundedBannerAdapter(urls: MutableList<String>) : BannerAdapter<String, RoundedBannerAdapter.BannerViewHolder>(urls) {
//
//        override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
//            val imageView = ImageView(parent!!.context)
//                .apply {
//                layoutParams = ViewGroup.LayoutParams(
//                    ViewGroup.LayoutParams.MATCH_PARENT,
//                    ViewGroup.LayoutParams.MATCH_PARENT
//                )
//                scaleType = ImageView.ScaleType.CENTER_CROP
//            }
//            return BannerViewHolder(imageView)
//        }
//
//        override fun onBindView(
//            holder: BannerViewHolder?,
//            data: String?,
//            position: Int,
//            size: Int
//        ) {
//            Glide.with(activity!!).load(data).into( holder?.imageView!!)
//        }
//
//
//        inner class BannerViewHolder(var imageView: ImageView) :
//            RecyclerView.ViewHolder(imageView)
//    }

    protected var mView: View? = null
    protected var mContext: Context? = null
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        mView!!.findViewById<Banner<String,RoundedBannerAdapter>>(R.id.banner).apply {
            setAdapter(RoundedBannerAdapter(context,Data.imagess)) // 设置图片的适配器
            setLoopTime(1500) // 轮播间隔时间
            setIndicatorSpace(20) // 指示器圆圈之间的间隔
            setIndicatorNormalWidth(12) // 未选中状态下，指示器圆圈的直径大小
            setIndicatorSelectedWidth(12) // 选中状态下，指示器圆圈的直径大小
            setIndicator(CircleIndicator(context))
        }

        //        banner.setIndicatorRadius(100);
//        banner.setImageLoader(new GlideImageLoader());
//        banner.setImages(Data.images);
//        //banner.setBannerTitles(imageTitle);
//        banner.setIndicatorGravity(BannerConfig.CENTER);
//        //设置是否自动轮播（不设置则默认自动）
//        banner.isAutoPlay(true);
//        //设置轮播图片间隔时间（不设置默认为2000）
//        banner.setDelayTime(2500);
//        //设置圆角
//        banner.setOutlineProvider(new ViewOutlineProvider() {
//            @Override
//            public void getOutline(View view, Outline outline) {
//                outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 30);
//            }
//        });
//        banner.setClipToOutline(true);
//
//        banner.setIndicatorGravity(BannerConfig.CENTER);
//        banner.setImages(Data.images)
//                .setOnBannerListener(new OnBannerListener() {
//                    @Override
//                    public void OnBannerClick(int position) {
//                        Toast.makeText(getActivity(), "你点了第" + (position + 1) + "张轮播图", Toast.LENGTH_SHORT).show();
//                    }
//                })
//                .start();
        val imageButton = mView!!.findViewById<ImageButton>(R.id.imb_queding)
        imageButton.setOnClickListener { //Toast.makeText(getActivity(), "success2",Toast.LENGTH_LONG).show();
            val intent = Intent(activity, New1::class.java)
            startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initView()
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mContext = activity
        mView = inflater.inflate(R.layout.home, container, false)
        return mView
    }

    override fun onPause() {
        super.onPause()
    }

    companion object {
        private const val TAG = "TabFirstFragment"
    }
}
